//人员功能相关配置
// eslint-disable-next-line no-unused-vars
import axios from "axios";
import {nanoid} from "nanoid";

export default {
    namespaced: true,
    actions: {
        addPersonWang: function (context, val) {
            // console.log(val)
            if (val.name.indexOf('王') === 0) {
                context.commit('ADDPERSON', val)
            } else {
                alert('添加的人必须姓王')
            }

        },
        addPersonServer: function (context) {
            axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
                (resp) => {
                    console.log(resp.data)
                    context.commit('ADDPERSON', {id: nanoid(), name: resp.data})
                },
                (error) => {
                    console.log(error.message)
                }
            )


        }
    },
    mutations: {
        'ADDPERSON': function (state, val) {
            state.personList.unshift(val)
        }
    },
    state: {
        personList: [
            {id: '001', name: '张三'}
        ]
    },
    getters: {
        firstPersonName: function (state) {
            return state.personList[0].name
        }
    },
}